<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>我要充值</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/statics/layui/css/layui.css" media="all">
</head>

<body>

  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>我要充值</legend>
  </fieldset>
  <blockquote class="layui-elem-quote">注意：充值申请24小时内处理，请注意短信通知！</blockquote>
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <label class="layui-form-label">选择币种</label>
      <div class="layui-input-inline">
        <select id="typeId" name="typeId">
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">充值数量</label>
        <div class="layui-input-inline" style="width: 100px;">
          <input type="text" name="money" value="100" lay-verify="required|number" placeholder="￥" autocomplete="off" class="layui-input">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      </div>
    </div>
  </form>
  <script src="/statics/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="../js/config.js"></script>
  <script type="text/javascript" src="../js/utils.js"></script>

  <script>

    $(function(){
      DataUtils.getMoneyTypeList(function(data){
        if(data && data.length>0){
          $.each(data, function(i, item){
            $("#typeId").append("<option value='"+item.typeId+"'>"+item.typeName+"</option>");
          });
        }        
      });
    });

    layui.use(['form'], function () {
      var form = layui.form, layer = layui.layer;

      //监听提交
      form.on('submit(demo1)', function (data) {
        var typeName = $("#typeId").find("option:selected").text();
        layer.confirm('确定要充值 '+data.field.money+' ('+typeName+') 吗?', {icon: 3, title:'提示'}, function(index){
          var url = Config.WEB_SERVER_API + Config.URI.USER_MONEY_RECHARGE_SAVE;
          HttpUtils.httpPost(url, data.field, function (result, success) {
            if (success) {
              layer.alert('恭喜您，提交成功，请等待管理员审核！', { title: '提示' });
            }else{
              layer.alert(result.resultMsg, { title: '出错了', icon: 5 });
            }
          });
          layer.close(index);
        });
        
        return false;
      });

      //表单初始赋值
      // form.val('example', {"money":100});
    });
  </script>

</body>

</html>